<?php
/*	-----------------------------------------------------
 *	 General Functions
 *	-----------------------------------------------------
 *	insert($table, $data);
 *
 *	update($table, $data, $id);
 *
 *	delete($table, $id);
 *
 *	getTableList($table, $display='name', $value='id');
 *
 */
class Mod_General extends CI_Model{	
	
	public function insert($table, $data){
		$this->db->insert(table($table), $data); 
		return $this->db->affected_rows();
	}
	
	public function update($table, $data, $id){		
        $this->db->where(field('id'), $id);
		$this->db->update(table($table), $data); 
		return $this->db->affected_rows();
	}
	
    public function delete($table, $id) {
        $this->db->where(field('id'), $id);
        $this->db->delete($table);
		return $this->db->affected_rows();
    }
	
	public function getTableList($table, $display='name', $value='id'){
		$this->db->select(field($value) . ', ' . field($display));
		$this->db->from(table($table));
		$this->db->order_by(field($display));
		$result = $this->db->get();
		
		$return = array(''=>'');
		if($result->num_rows() > 0){
			foreach($result->result_array() as $row){
				$return[$row[field($value)]] = $row[field($display)];
			}
		}
		return $return;
	}
}